using System;
using Whitemice.MOGI;

namespace Whitemice.MOGI.ZOGI
{	
	public class Contact : Whitemice.MOGI.ZOGI.Company, IContact
	{
		public Contact(IServer server, Payload payload) 
			: base(server, payload)
		{
		}
	
		public string FirstName 
		{ 
			get { return payload.GetStringForKey("firstName"); } 
			set { payload.SetValueForKey("firstName", value); }
		}
		
		public string MiddleName
		{ 
			get { return payload.GetStringForKey("middleName"); } 
			set { payload.SetValueForKey("middleName", value); }
		}
		
		public string LastName
		{ 
			get { return payload.GetStringForKey("lastName"); } 
			set { payload.SetValueForKey("lastName", value); }
		}
		
		public string DisplayName
		{ 
			get { return payload.GetStringForKey("displayName"); } 
			set { payload.SetValueForKey("displayName", value); }
		}
		
		public string URL
		{ 
			get { return payload.GetStringForKey("url"); } 
			set { payload.SetValueForKey("url", value); }
		}

		public DateTime BirthDate
		{ 
			get { return payload.GetDateTimeForKey("birthDate"); } 
			set { payload.SetValueForKey("birthDate", value); }
		}
		
		public string Degree
		{ 
			get { return payload.GetStringForKey("degree"); } 
			set { payload.SetValueForKey("degree", value); }
		}
		
		public Salutation Salutation
		{ 
			get 
			{
				Salutation salutation;
				salutation = Salutation.Undefined;
				switch(payload.GetStringForKey("salutation")) 
				{
       		case "01_dear_ms":
         		salutation = Salutation.Ms;
        		break;
					case "02_dear_mrs":
						salutation = Salutation.Mrs;
						break;
					case "03_dear_mr":
						salutation = Salutation.Mr;
						break;
					case "04_dear_prof":
						salutation = Salutation.Prof;
						break;
					case "05_dear_dr":
						salutation = Salutation.Dr;
						break;
				}
				return salutation;			
			}
			set 
			{
				switch(value) 
				{
					case Salutation.Ms:
						payload.SetValueForKey("salutation", "01_dear_ms");
						break;
					case Salutation.Mrs:
						payload.SetValueForKey("salutation", "02_dear_mrs");
						break;
					case Salutation.Mr:
						payload.SetValueForKey("salutation", "03_dear_mr");
						break;
					case Salutation.Prof:
						payload.SetValueForKey("salutation", "04_dear_prof");
						break;
					case Salutation.Dr:
						payload.SetValueForKey("salutation", "05_dear_dr");
						break;
					default:
						payload.SetValueForKey("salutation", "");
						break;
				}
			}
		}
		
		public Gender Gender
		{ 
			get 
			{
				Gender gender;
				gender = Gender.Undefined;
				switch(payload.GetStringForKey("gender")) 
				{
					case "undefined":
							gender = Gender.Undefined;
						break;
					case "male":
							gender = Gender.Male;
						break;
					case "female":
							gender = Gender.Female;
						break;
				}
				return gender;
			}
			set 
			{
				switch(value) 
				{
					case Gender.Male:
						payload.SetValueForKey("gender", "male");
						break;
					case Gender.Female:
						payload.SetValueForKey("gender", "female");
						break;
					case Gender.Undefined:
						payload.SetValueForKey("gender", "undefined");
						break;
				}
			}
		}
		
		public string Email1
		{ 
			get 
			{
				if (payload.HasCompanyValue("email1"))
					return payload.CompanyValue("email1").Value;
				return "";
			}
			set 
			{
				if (payload.HasCompanyValue("email1"))
					payload.CompanyValue("email1").Value = value;
			}
		}
		
		public string Email2
		{ 
			get 
			{
				if (payload.HasCompanyValue("email2"))
					return payload.CompanyValue("email2").Value;
				return "";
			}
			set 
			{
				if (payload.HasCompanyValue("email2"))
					payload.CompanyValue("email2").Value = value;
			}
		}
		
		public string Email3
		{ 
			get 
			{
				if (payload.HasCompanyValue("email3"))
					return payload.CompanyValue("email3").Value;
				return "";
			}
			set 
			{
				if (payload.HasCompanyValue("email3"))
					payload.CompanyValue("email3").Value = value;
			}
		}
		
		public string JobTitle
		{ 
			get 
			{
				if (payload.HasCompanyValue("job_title"))
					return payload.CompanyValue("job_title").Value;
				return "";
			}
			set 
			{
				if (payload.HasCompanyValue("job_title"))
					payload.CompanyValue("job_title").Value = value;
			}
		}
		
		public string OtherTitle1
		{ 
			get 
			{
				if (payload.HasCompanyValue("other_title1"))
					return payload.CompanyValue("other_title1").Value;
				return "";
			}
			set 
			{
				if (payload.HasCompanyValue("other_title1"))
					payload.CompanyValue("other_title1").Value = value;
			}
		}
		
		public string OtherTitle2
		{ 
			get 
			{
				if (payload.HasCompanyValue("other_title2"))
					return payload.CompanyValue("other_title2").Value;
				return "";
			}
			set 
			{
				if (payload.HasCompanyValue("other_title2"))
					payload.CompanyValue("other_title2").Value = value;
			}
		}
	}
}
